<?php

//*******************************************************
//* JAccelerator Component
//* http://fun.kubera.org
//* (C) Radoslaw Kubera
//* license http://www.gnu.org/copyleft/gpl.html GNU/GPL
//*******************************************************

/** ensure this file is being included by a parent file */
defined('_VALID_MOS') or die('Direct Access to this location is not allowed.');

global $mosConfig_absolute_path;

class HTML_joomlacache_admin {
	function sizetostr($MB) {
		$MB = ''.$MB;
		$size = strlen($MB);
		$k = 0;
		$show = '';
		for ($i = 1; $i <= $size; $i++) {
			$k++;
			$show = $MB[$size - $i].$show;
			if($k == 3) {
				$k = 0;
				$show = ' '.$show;
			}
		}
		if($show == '')
			$show = '0';
		return $show;
	}

	function navbar() {

?>
    <script language="javascript" type="text/javascript">
    function submitbutton(pressbutton) 
    {
      var form = document.adminForm;
      if ( typeof( form.limitstart ) != "undefined" ) form.limitstart.value=0;
      form.task.value=pressbutton;
      form.submit();
    }
    //-->
    </script>
   <?php

	}

	function blank() {
		HTML_joomlacache_admin::navbar();

?>

    <form action="index2.php?option=com_joomlacache" method="post" name="adminForm">
    <table class="adminheading">
      <tr>
        <th>JAccelerator - <?php

		echo _CONFIG

?> </th>
      </tr>
    </table>
    <input type="hidden" name="task" value="blank">
    <input type="hidden" name="hidemainmenu" value="false">
    </form>
    <?php

	}

	function about() {
		global $mosConfig_absolute_path, $mosConfig_lang;
		HTML_joomlacache_admin::navbar();

?>
    <form action="index2.php?option=com_joomlacache" method="post" name="adminForm">
    <table class="adminheading">
      <tr>
        <th>JAccelerator - <?php

		echo _JOOMLACACHE_ABOUT

?> </th>
      </tr>
      <tr>
        <td>
          <?php

		echo 'VERSION: '._JOOMLACACHE_VERSION.'<br/>';

		$path = $mosConfig_absolute_path.'/components/com_joomlacache/';
		if(file_exists($path.'license.txt')) {
			echo 'LICENSE:<br/>';
			$lic = str_replace("\n", '<br/>', implode("", file($path.'license.txt')));
			echo $lic;
		}

?>
        </td>
      </tr>
      <tr>
        <td align="left">
        <?php

		if(file_exists($mosConfig_absolute_path."/administrator/components/com_joomlacache/language/".$mosConfig_lang.".about.txt")) {
			$path = $mosConfig_absolute_path."/administrator/components/com_joomlacache/language/".$mosConfig_lang.".about.txt";
		} else {
			$path = $mosConfig_absolute_path."/administrator/components/com_joomlacache/language/english.about.txt";
		}
		//          $path = $mosConfig_absolute_path.'/administrator/components/com_joomlacache/about.txt';
		$file = file($path);
		$txt = implode('<br/>', $file);
		echo $txt;

?>
        </td>
      </tr>
    </table>
    <input type="hidden" name="task" value="about">
    <input type="hidden" name="hidemainmenu" value="false">
    </form>
    <?php

	}

	function config($params) {
		HTML_joomlacache_admin::navbar();

?>

    <form action="index2.php?option=com_joomlacache" method="post" name="adminForm">
    <table class="adminheading">
      <tr>
        <th>JAccelerator - <?php

		echo _JOOMLACACHE_CONFIG

?> </th>
      </tr>
    </table>

    <table cellpadding="2" cellspacing="4" border="0" width="100%" class="adminform">
      <tr>
        <th colspan="2"><?php

		echo _JOOMLACACHE_CONFIG

?></th>
      </tr>
      <tr>
        <td width="400"><?php

		echo _JOOMLACACHE_COMPONENT_ON

?></th>
        <td>
          <?php

		if($params['published'] == 1) {
			$img = 'tick.png';
		} else {
			$img = 'publish_x.png';
		}
		echo '<a href ="index2.php?option=com_joomlacache&task=chpub"><img src ="images/'.$img.'" border="0"></a>';

?>
        </td>
      </tr>
      <tr>
        <td><?php

		echo _JOOMLACACHE_DEFAULT_TIME

?></td>
        <td>
        <select name ="params[days]" class="inputbox">
          <?php

		if(isset($params['days']))
			$value = $params['days'];
		else
			$value = 0;
		for ($k = 0; $k <= 60; $k++) {
			if($k == $value)
				$selected = 'selected';
			else
				$selected = '';
			echo '<option value="'.$k.'" '.$selected.'>'.$k.'</option>';
		}

?>
        </select><?php

		echo _JOOMLACACHE_DAYS

?>

        <select name ="params[hours]" class="inputbox">
          <?php

		if(isset($params['hours']))
			$value = $params['hours'];
		else
			$value = 0;
		for ($k = 0; $k <= 23; $k++) {
			if($k == $value)
				$selected = 'selected';
			else
				$selected = '';
			echo '<option value="'.$k.'" '.$selected.'>'.$k.'</option>';
		}

?>
        </select><?php

		echo _JOOMLACACHE_HOURS

?>

        <select name ="params[minutes]" class="inputbox">
          <?php

		if(isset($params['minutes']))
			$value = $params['minutes'];
		else
			$value = 0;
		for ($k = 0; $k <= 59; $k++) {
			if($k == $value)
				$selected = 'selected';
			else
				$selected = '';
			echo '<option value="'.$k.'" '.$selected.'>'.$k.'</option>';
		}

?>
        </select><?php

		echo _JOOMLACACHE_MINUTES

?>
        </td>
      </tr>
      <tr>
        <td><?php

		echo _JOOMLACACHE_MAX_SIZE

?></td>
        <td><input type="text" size="30" class="text_area" name="params[size]" value="<?php

		if(isset($params['size']))
			echo intval($params['size']);
		else
			echo '0';

?>">
      </tr>
      <tr>
        <td><?php

		echo _JOOMLACACHE_GENERATION_TIME

?></td>
        <td>
          <select name ="params[gentime]" class="inputbox">
          <?php

		if(isset($params['gentime']) && $params['gentime']) {
			$value1 = '';
			$value2 = 'selected';
		} else {
			$value2 = '';
			$value1 = 'selected';
		}
		echo '<option value="0" '.$value1.'>'._JOOMLACACHE_NO.'</option>';
		echo '<option value="1" '.$value2.'>'._JOOMLACACHE_YES.'</option>';

?>
          </select>
        </td>
      </tr>

      <tr>
        <td><?php

		echo _JOOMLACACHE_HIDE_CREDITS

?></td>
        <td>
          <select name ="params[hidelink]" class="inputbox">
          <?php

		if(!isset($params['hidelink']) || $params['hidelink'] == 1) {
			$value2 = '';
			$value1 = 'selected';
		} else {
			$value1 = '';
			$value2 = 'selected';
		}
		echo '<option value="1" '.$value1.'>'._JOOMLACACHE_NO.'</option>';
		echo '<option value="0" '.$value2.'>'._JOOMLACACHE_YES.'</option>';

?>
          </select>
       </td>
      </tr>
      <?php

		if($value2 == 'selected') {
			echo '<tr><td>';
			echo _JOOMLACACHE_CREDITS_INFO.': ';
			echo '</td><td>';
			global $mosConfig_absolute_path;
			require_once ($mosConfig_absolute_path.'/mambots/system/joomlacache.php');
			$link = JoomlaCacheGetLink();
			$link1 = str_replace('<', '&lt;', $link);
			$link1 = str_replace('>', '&gt;', $link1);

			echo $link1.'</td></tr><tr><td>'._JOOMLACACHE_THANK_YOU.'.</td><td>'.$link;
			echo '</td></tr>';
		}

?>
      <tr>
        <th colspan="2"><?php

		echo _JOOMLACACHE_AUTO_FLUSH_OPTION

?>:</th>
      </tr>
      <tr>
        <?php

		if(isset($params['flush_after_hour']))
			$value = 'checked';
		else
			$value = '';

?>
        <td><input type ="checkbox" name="params[flush_after_hour]" <?php

		echo $value

?>><?php

		echo _JOOMLACACHE_FLUSH_AFTER_HOUR

?></td>
        <td>
        <select name ="params[flush_after_hour_option]" class="inputbox">
          <?php

		if(isset($params['flush_after_hour_option']))
			$value = $params['flush_after_hour_option'];
		else
			$value = 0;
		for ($k = 0; $k <= 23; $k++) {
			if($k == $value)
				$selected = 'selected';
			else
				$selected = '';
			echo '<option value="'.$k.'" '.$selected.'>'.$k.'</option>';
		}

?>
        </select>
        </td>
      </tr>
      <tr>
        <?php

		if(isset($params['flush_after_hours']))
			$value = 'checked';
		else
			$value = '';

?>
        <td><input type ="checkbox" name="params[flush_after_hours]" <?php

		echo $value

?>><?php

		echo _JOOMLACACHE_FLUSH_AFTER_HOURS

?></td>
        <td>
        <select name ="params[flush_after_hours_option]" class="inputbox">
          <?php

		if(isset($params['flush_after_hours_option']))
			$value = $params['flush_after_hours_option'];
		else
			$value = 0;
		for ($k = 1; $k <= 99; $k++) {
			if($k == $value)
				$selected = 'selected';
			else
				$selected = '';
			echo '<option value="'.$k.'" '.$selected.'>'.$k.'</option>';
		}

?>
        </select>
        </td>
      </tr>
      <tr>
        <?php

		if(isset($params['flush_after_expired']))
			$value = 'checked';
		else
			$value = '';

?>
        <td><input type ="checkbox" name="params[flush_after_expired]" <?php

		echo $value

?>><?php

		echo _JOOMLACACHE_FLUSH_AFTER_EXPIRED

?></td>
      </tr>
      </tr>
        <th colspan="2"><?php

		echo _JOOMLACACHE_AUTO_REMOVE_OPTION

?>:</th>
      </tr>
      <tr>
        <?php

		if(isset($params['remove_after_hour']))
			$value = 'checked';
		else
			$value = '';

?>
        <td><input type ="checkbox" name="params[remove_after_hour]" <?php

		echo $value

?>><?php

		echo _JOOMLACACHE_REMOVE_AFTER_HOUR

?></td>
        <td>
        <select name ="params[remove_after_hour_option]" class="inputbox">
          <?php

		if(isset($params['remove_after_hour_option']))
			$value = $params['remove_after_hour_option'];
		else
			$value = 0;
		for ($k = 0; $k <= 23; $k++) {
			if($k == $value)
				$selected = 'selected';
			else
				$selected = '';
			echo '<option value="'.$k.'" '.$selected.'>'.$k.'</option>';
		}

?>
        </select>
        </td>
      </tr>
      <tr>
        <?php

		if(isset($params['remove_after_hours']))
			$value = 'checked';
		else
			$value = '';

?>
        <td><input type ="checkbox" name="params[remove_after_hours]" <?php

		echo $value

?>><?php

		echo _JOOMLACACHE_REMOVE_AFTER_HOURS

?></td>
        <td>
        <select name ="params[remove_after_hours_option]" class="inputbox">
          <?php

		if(isset($params['remove_after_hours_option']))
			$value = $params['remove_after_hours_option'];
		else
			$value = 0;
		for ($k = 1; $k <= 99; $k++) {
			if($k == $value)
				$selected = 'selected';
			else
				$selected = '';
			echo '<option value="'.$k.'" '.$selected.'>'.$k.'</option>';
		}

?>
        </select>
        </td>
      </tr>
      <tr>
    
    </table>

    <input type="hidden" name="task" value="blank">
    <input type="hidden" name="hidemainmenu" value="false">
    </form>
    <?php

	}

	function components($components, $global) {
		HTML_joomlacache_admin::navbar();

?>
 
    <script language="JavaScript" type="text/javascript">
      function SubmitAdminFormAfterConfirm (message,remove_option)
      {
        var yesno = confirm (message);
        if (yesno == true)
        {
          document.adminForm.task.value='remove_cache';
          document.adminForm.remove_option.value=remove_option;
          document.adminForm.submit();
        }
      }
    </script>
    
    <form action="index2.php?option=com_joomlacache" method="post" name="adminForm">
    <table class="adminheading">
      <tr>
        <th>JAccelerator - <?php

		echo _JOOMLACACHE_COMPONENTS

?> </th>
      </tr>
    </table>
    <table cellpadding="2" cellspacing="4" border="0" width="100%" class="adminlist">
      <tr>
        <th align="left"><?php

		echo _JOOMLACACHE_COMPONENT

?></th>
        <th align="left"><?php

		echo _JOOMLACACHE_CACHE_TYPE

?></th>
        <th align="left"><?php

		echo _JOOMLACACHE_CACHETIME

?></th>
        <th align="center"><?php

		echo _JOOMLACACHE_CACHE_ITEMS

?></th>
        <th align="center"><?php

		echo _JOOMLACACHE_CACHE_HITS

?></th>
        <th align="center"><?php

		echo _JOOMLACACHE_CACHE_SIZE

?></th>
        <th align="center"><?php

		echo _JOOMLACACHE_CLEAR_CACHE_TITLE

?></th>
      </tr>
      <?php

		$j = 0;
		$i = 0;
		foreach ($components as $component) {
			echo '<tr class="row'.$j.'">';
			if($j == 0)
				$j = 1;
			else
				$j = 0;

			echo '<td>';
			echo '<b>'.$component->name.'</b> ('.$component->option.')';
			echo '</td>';
			if(isset($component->cache))
				$value = $component->cache;
			else
				$value = 0;

?>
        <td>
        <select name ="<?php

			echo $component->option

?>[cache]?>" class="inputbox">
          <option value="0" <?php

			if($value == 0)
				echo 'selected'

?>><?php

				echo _JOOMLACACHE_NONE

?></option>
          <option value="1" <?php

				if($value == 1)
					echo 'selected'

?>><?php

					echo _JOOMLACACHE_MAINBODY

?></option>
        </select>
        </td>

        <td>
        <select name ="<?php

					echo $component->option

?>[days]?>" class="inputbox">
          <?php

					if(isset($component->days))
						$value = $component->days;
					else
						$value = 0;
			for ($k = 0; $k <= 60; $k++) {
				if($k == $value)
					$selected = 'selected';
				else
					$selected = '';
				echo '<option value="'.$k.'" '.$selected.'>'.$k.'</option>';
			}

?>
        </select><?php

			echo _JOOMLACACHE_DAYS

?>

        <select name ="<?php

			echo $component->option

?>[hours]?>" class="inputbox">
          <?php

			if(isset($component->hours))
				$value = $component->hours;
			else
				$value = 0;
			for ($k = 0; $k <= 23; $k++) {
				if($k == $value)
					$selected = 'selected';
				else
					$selected = '';
				echo '<option value="'.$k.'" '.$selected.'>'.$k.'</option>';
			}

?>
        </select><?php

			echo _JOOMLACACHE_HOURS

?>

        <select name ="<?php

			echo $component->option

?>[minutes]?>" class="inputbox">
          <?php

			if(isset($component->minutes))
				$value = $component->minutes;
			else
				$value = 0;
			for ($k = 0; $k <= 59; $k++) {
				if($k == $value)
					$selected = 'selected';
				else
					$selected = '';
				echo '<option value="'.$k.'" '.$selected.'>'.$k.'</option>';
			}

?>
        </select><?php

			echo _JOOMLACACHE_MINUTES

?>
        </td>
        <td align="center">
          <?php

			echo $component->files

?>
        </td>
        <td align="center">
          <?php

			echo $component->hits

?>
        </td>
        <td align="center">
          <?php

			echo HTML_joomlacache_admin::sizetostr($component->size).' '._JOOMLACACHE_BYTES;

?> 
        </td>
        <td align="center">
          <input type="submit" class="button" name="clear_<?php

			echo $component->option

?>" value="<?php

			echo _JOOMLACACHE_FLUSH_CACHE

?>">
          <input type="button" class="button" value="<?php

			echo _JOOMLACACHE_REMOVE_CACHE

?>" onClick="SubmitAdminFormAfterConfirm('<?php

			echo _JOOMLACACHE_REMOVE_CACHE_MESSAGE

?>','<?php

			echo $component->option

?>' );">
        </td>

        <?php

			echo '</tr>';
		}

?>
      <tr>
        <th align="left"></th>
        <th align="left"></th>
        <th align="left"></th>
        <th align="center"><?php

		echo $global->files

?></th>
        <th align="center"><?php

		echo $global->hits

?></th>
        <th align="center"><?php

		echo HTML_joomlacache_admin::sizetostr($global->size).' '._JOOMLACACHE_BYTES;

?></th>
        <th align="center">
          <input type="submit" class="button" name="clear_all" value="<?php

		echo _JOOMLACACHE_FLUSH_CACHE

?>">
          <input type="button" class="button" value="<?php

		echo _JOOMLACACHE_REMOVE_CACHE

?>" onClick="SubmitAdminFormAfterConfirm('<?php

		echo _JOOMLACACHE_REMOVE_ALL_CACHE_MESSAGE

?>','' );">
        </th>
      </tr>

    </table>
    <input type="hidden" name="task" value="blank">
    <input type="hidden" name="remove_option" value="">
    <input type="hidden" name="hidemainmenu" value="false">
    </form>
    <?php

	}
	function modules($modules, $global) {
		HTML_joomlacache_admin::navbar();

?>
 
    <script language="JavaScript" type="text/javascript">
      function SubmitAdminFormAfterConfirm (message,remove_option)
      {
        var yesno = confirm (message);
        if (yesno == true)
        {
          document.adminForm.task.value='remove_module_cache';
          document.adminForm.remove_option.value=remove_option;
          document.adminForm.submit();
        }
      }
    </script>

    <form action="index2.php?option=com_joomlacache" method="post" name="adminForm">
    <table class="adminheading">
      <tr>
        <th>JAccelerator - <?php

		echo _JOOMLACACHE_MODULES

?> </th>
      </tr>
    </table>

    <table cellpadding="2" cellspacing="4" border="0" width="100%" class="adminlist">
      <tr>
        <th align="left" width="10" >ID</th>
        <th align="left"><?php

		echo _JOOMLACACHE_MODULE

?></th>
        <th align="left"><?php

		echo _JOOMLACACHE_CACHE_TYPE

?></th>
        <th align="left"><?php

		echo _JOOMLACACHE_CACHETIME

?></th>
        <th align="center"><?php

		echo _JOOMLACACHE_CACHE_ITEMS

?></th>
        <th align="center"><?php

		echo _JOOMLACACHE_CACHE_HITS

?></th>
        <th align="center"><?php

		echo _JOOMLACACHE_CACHE_SIZE

?></th>
        <th align="center"><?php

		echo _JOOMLACACHE_CLEAR_CACHE_TITLE

?></th>
      </tr>
      <?php

		$j = 0;
		$i = 0;
		foreach ($modules as $module) {
			echo '<tr class="row'.$j.'">';
			if($j == 0)
				$j = 1;
			else
				$j = 0;
			echo '<td>'.$module->id.'</td>';
			echo '<td>';
			if($module->published == 1) {
				$img = 'tick.png';
				$title = _JOOMLACACHE_PUBLISHED;
			} else {
				$img = 'publish_x.png';
				$title = _JOOMLACACHE_UNPUBLISHED;

			}
			echo '<img alt ="'.$title.'" title ="'.$title.'" src ="images/'.$img.'" border="0">';

			echo '&nbsp;<b>'.$module->title.'</b>';

			if($module->module)
				echo ' ('.$module->module.')';

			echo '</td>';
			if(isset($module->cache))
				$value = $module->cache;
			else
				$value = 0;

?>
        <td>
        <select name ="id_<?php

			echo $module->id

?>[cache]?>" class="inputbox">
          <option value="0" <?php

			if($value == 0)
				echo 'selected'

?>><?php

				echo _JOOMLACACHE_NONE

?></option>
          <option value="1" <?php

				if($value == 1)
					echo 'selected'

?>><?php

					echo _JOOMLACACHE_MODULE_FULL_CACHE

?></option>
          <option value="2" <?php

					if($value == 2)
						echo 'selected'

?>><?php

						echo _JOOMLACACHE_MODULE_SINGLE_VIEW

?></option>
        </select>
        </td>

        <td>
        <select name =id_<?php

						echo $module->id

?>[days]?>" class="inputbox">
          <?php

						if(isset($module->days))
							$value = $module->days;
						else
							$value = 0;
			for ($k = 0; $k <= 60; $k++) {
				if($k == $value)
					$selected = 'selected';
				else
					$selected = '';
				echo '<option value="'.$k.'" '.$selected.'>'.$k.'</option>';
			}

?>
        </select><?php

			echo _JOOMLACACHE_DAYS

?>

        <select name ="id_<?php

			echo $module->id

?>[hours]?>" class="inputbox">
          <?php

			if(isset($module->hours))
				$value = $module->hours;
			else
				$value = 0;
			for ($k = 0; $k <= 23; $k++) {
				if($k == $value)
					$selected = 'selected';
				else
					$selected = '';
				echo '<option value="'.$k.'" '.$selected.'>'.$k.'</option>';
			}

?>
        </select><?php

			echo _JOOMLACACHE_HOURS

?>

        <select name =id_<?php

			echo $module->id

?>[minutes]?>" class="inputbox">
          <?php

			if(isset($module->minutes))
				$value = $module->minutes;
			else
				$value = 0;
			for ($k = 0; $k <= 59; $k++) {
				if($k == $value)
					$selected = 'selected';
				else
					$selected = '';
				echo '<option value="'.$k.'" '.$selected.'>'.$k.'</option>';
			}

?>
        </select><?php

			echo _JOOMLACACHE_MINUTES

?>
        </td>
        <td align="center">
          <?php

			echo $module->files

?>
        </td>
        <td align="center">
          <?php

			echo $module->hits

?>
        </td>
        <td align="center">
          <?php

			echo HTML_joomlacache_admin::sizetostr($module->size).' '._JOOMLACACHE_BYTES;

?> 
        </td>
        <td align="center">
          <input type="submit" class="button" name="module_clear_<?php

			echo $module->id

?>" value="<?php

			echo _JOOMLACACHE_FLUSH_CACHE

?>">
          <input type="button" class="button" value="<?php

			echo _JOOMLACACHE_REMOVE_CACHE

?>" onClick="SubmitAdminFormAfterConfirm('<?php

			echo _JOOMLACACHE_REMOVE_CACHE_MESSAGE

?>','<?php

			echo $module->id

?>' );">
        </td>

        <?php

			echo '</tr>';
		}

?>
      <tr>
        <th align="left"></th>
        <th align="left"></th>
        <th align="left"></th>
        <th align="left"></th>
        <th align="center"><?php

		echo $global->files

?></th>
        <th align="center"><?php

		echo $global->hits

?></th>
        <th align="center"><?php

		echo HTML_joomlacache_admin::sizetostr($global->size).' '._JOOMLACACHE_BYTES;

?></th>
        <th align="center">
          <input type="submit" class="button" name="module_clear_all" value="<?php

		echo _JOOMLACACHE_FLUSH_CACHE

?>">
          <input type="button" class="button" value="<?php

		echo _JOOMLACACHE_REMOVE_CACHE

?>" onClick="SubmitAdminFormAfterConfirm('<?php

		echo _JOOMLACACHE_REMOVE_ALL_CACHE_MESSAGE

?>','' );">
        </th>
      </tr>

    </table>
    <input type="hidden" name="task" value="blank">
    <input type="hidden" name="remove_option" value="">
    <input type="hidden" name="hidemainmenu" value="false">
    </form>
    <?php

	}
}

?>
